feat(js): add lifecycle-managed js.io() to the JS DSL#26
Merged
Conversation
Comment on lines
+211
to
+212
| test "exportModule cleanup hook now also backs shared js.io lifecycle" { | ||
| try std.testing.expect(true); |
Contributor
Author
There was a problem hiding this comment.
Was actually supposed to delete the full test case. Now added a particular test case for retain/cleanup scenario.
|
|
||
| const gpa: std.mem.Allocator = std.heap.page_allocator; | ||
|
|
||
| const SpinLock = struct { |
Member
There was a problem hiding this comment.
wondering why not just use std.Io.Mutex here instead of handrolling a spin lock?
Contributor
Author
There was a problem hiding this comment.
The std.io.Mutex was not used earlier because it's .lock take an io as parameter. And in our case we are actually protecting the io itselt. Now used std.Io.Threaded.mutexLock which does not need io.
Replace the vacuous expect(true) placeholder with a real check that io() returns the same backing instance across calls while retained, guarding the shared-io lifecycle the env cleanup hook drives. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Replace the hand-rolled spin lock with std.Io.Mutex locked via std.Io.Threaded.mutexLock/mutexUnlock, which need no Io argument and block on a futex instead of busy-spinning. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
We already expose lifecycle-scoped DSL context helpers like
js.env()andjs.allocator(). This change adds the analogous I/O surface so DSL code can use std.Io facilities without requiring module authors to bootstrap or own a separate runtime.Summary
js.io()accessor to the JS DSLjs.io()with a shared std.Io.Threaded instance retained for the lifetime of active addon environmentsjs.exportModule(...)so consumers do not need any manual setupAPI Notes
js.io()retain()/release()remain internal implementation detailsjs.io()is only valid during the normal addon lifecycle window and will panic if used before registration or after final cleanup